﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RenderAction.Models;

namespace RenderAction.Models
{
    public class ClimbRepository
    {
        private ClimbList _climbs;
        public ClimbRepository()
        {
            _climbs = new ClimbList();

            _climbs.Add(new Climb()
                            {
                                Name = "Passo dello Stelvio",
                                Length = 24.3,
                                AverageGrade = 7.4,
                                Gain = 1808,
                                Difficutly = DifficutlyLevel.Hard
                            }
                );

            _climbs.Add(new Climb()
                            {
                                Name = "Mont Ventoux",
                                Length = 21.2,
                                AverageGrade = 7.2,
                                Gain = 1532,
                                Difficutly = DifficutlyLevel.Medium
                            }
                );

            _climbs.Add(new Climb()
                            {
                                Name = "Mortirolo",
                                Length = 12.4,
                                AverageGrade = 10.5,
                                Gain = 1300,
                                Difficutly = DifficutlyLevel.Strenuous
                            }
                );

            _climbs.Add(new Climb()
                            {
                                Name = "Mount Washington",
                                Length = 12.4,
                                AverageGrade = 11.5,
                                Gain = 1420,
                                Difficutly = DifficutlyLevel.ArmstrongLevel
                            }
                );

            _climbs.Add(new Climb()
                            {
                                Name = "Brinzio",
                                Length = 8.28,
                                AverageGrade = 3.5,
                                Gain = 292,
                                Difficutly = DifficutlyLevel.Easy
                            }
                );
        }

        public ClimbList GetTopClimbs()
        {
            var query = from c in _climbs
                        orderby c.Name
                        select c;
            return new ClimbList(query);
        }

        public Climb GetClimb(string name)
        {
            var climb = from c in _climbs
                        where c.Name == name
                        select c;
            return climb.First();
        }
    }
}